package com.jic.product.controller.manage;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.product.entity.ProductCalibration;
import com.jic.product.manage.request.ProductCalibrationRequest;
import com.jic.product.manage.response.ProductCalibrationResponse;
import com.jic.product.manage.response.ProductResponse;
import com.jic.product.service.ProductCalibrationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * description: 校标商品
 *
 * @author: jackHe
 * @time: 2020/5/8 15:44
 */
@RestController
@RequestMapping("/productCalibration")
@Api(value = "校标商品", description = "校标商品", tags = "校标商品")
public class ProductCalibrationController {

  @Autowired
  private ProductCalibrationService productCalibrationService;

  @ApiOperation("商品详情-校标商品分页")
  @PostMapping("/queryPage")
  public RestResult<PageResult<ProductResponse>> queryPage(@RequestBody ProductCalibrationRequest request) {
    Page page = new Page();
    page.setStart(request.getStart());
    page.setLimit(request.getLimit());
    return productCalibrationService.queryPage(request, page);
  }

  @ApiOperation("商品详情-校标商品")
  @PostMapping("/query")
  public RestResult<List<ProductCalibrationResponse>> query(@RequestBody ProductCalibrationRequest request) {
    ProductCalibration calibration = new ProductCalibration();
    BeanUtils.copyProperties(request, calibration);
    return productCalibrationService.query(calibration);
  }

  @ApiOperation("商品详情-新增校标商品")
  @PostMapping("/insert")
  public RestResult<String> insert(@RequestBody ProductCalibrationRequest request) {
    return productCalibrationService.insert(request);
  }

  @ApiOperation("商品详情-修改校标商品")
  @PostMapping("/delete")
  public RestResult<String> delete(@RequestBody ProductCalibrationRequest request) {
    ProductCalibration calibration = new ProductCalibration();
    BeanUtils.copyProperties(request, calibration);
    return productCalibrationService.delete(calibration);
  }

  @ApiOperation("商品详情-修改校标商品")
  @PostMapping("/update")
  public RestResult<String> update(@RequestBody ProductCalibrationRequest request) {
    ProductCalibration calibration = new ProductCalibration();
    BeanUtils.copyProperties(request, calibration);
    return productCalibrationService.update(calibration);
  }
}
